/*
 * =====================================================================================
 *
 *       Filename:  HanFeiziObservable.cpp
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  12/30/2021 05:54:54 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  first_name last_name (fl), fl@my-company.com
 *        Company:  my-company
 *
 * =====================================================================================
 */

#include "HanFeiziObservable.h"
#include <iostream>
#include "Log.h"

static const string TAG = "HanFeiziObservable";

using std::string;
using std::cout;
using std::endl;
HanFeiziObservable::HanFeiziObservable(void) {
}

HanFeiziObservable::~HanFeiziObservable(void) {
}

void HanFeiziObservable::AddObserver(IObserver* pObserver) {
    m_observerList.push_back(pObserver);
}

void HanFeiziObservable::DeleteObserver(IObserver* pObserver) {
    ObserverList_C_iterator it = m_observerList.begin();

    for (; it != m_observerList.end(); it++) {
        string name = (*it)->GetName();

        if (name.compare(pObserver->GetName()) == 0) {
            //找到了删除。
        }
    }
}

//通知观察者
void HanFeiziObservable::NotifyObservers(string context) {
    ObserverList_C_iterator it = m_observerList.begin();

    for (; it != m_observerList.end(); it++) {
        (*it)->Update(context);
    }
}

void HanFeiziObservable::HaveBreakfast() {
    LogI("%s", "韩非子：我 开始吃饭了...");
    this->NotifyObservers("韩非子在吃饭");
}

void HanFeiziObservable::HaveFun() {
    cout << "韩非子：开始娱乐了..." << endl;
    this->NotifyObservers("韩非子在娱乐");
}
